﻿using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using POS.BusinessComponents;
using POS.BusinessEntities;
using POS.DataObjects;
using Rhino.Mocks;

namespace POS.BusinessComponentsTest
{
    [TestClass]
    public class BCEntidadTest
    {
        #region Declarations
        
        private readonly MockRepository mocks = new MockRepository();
        private const int EmpresaId = 1;
        
        #endregion
        
        #region Test Methods

        [TestMethod]
        public void GetList()
        {
            var dummyFilter = "dummy";
            var dummyEntity = TipoEntidad.Marca;
            var doMock = (DOEntidad)mocks.StrictMock(typeof(DOEntidad), new object[] { dummyEntity });
            var expected = new List<BEEntidad>();

            Expect.Call(doMock.GetList(EmpresaId, dummyFilter)).Return(expected).Repeat.Once();
            
            doMock.Replay();
            new BCEntidad(doMock).GetList(dummyFilter);
            doMock.VerifyAllExpectations();
        }
        
        [TestMethod]
        public void Delete()
        {
           // var localMocks = new MockRepository();
            var dummyEntityType = TipoEntidad.Marca;
            var entityId = 1;
            var user = "testUser";
            var doMock = (DOEntidad)mocks.StrictMock(typeof(DOEntidad), new object[] { dummyEntityType });

            doMock.Delete(entityId, user);
            LastCall.IgnoreArguments();

            mocks.ReplayAll();
            new BCEntidad(doMock).Delete(entityId);
            mocks.VerifyAll();
        }
        
        [TestMethod]
        public void Save()
        {
            var dummyEntityType = TipoEntidad.Marca;
            var dummyEntity = new BEEntidad { Id = 999, Nombre = "testName" };
            var dummyEmpresaId = 99;
            var user = "testUser";

            var doMock = (DOEntidad)mocks.StrictMock(typeof(DOEntidad), new object[] { dummyEntityType});
            doMock.Save(dummyEntity, dummyEmpresaId, user);
            LastCall.IgnoreArguments();
            mocks.ReplayAll();
            new BCEntidad(doMock).Save(dummyEntity);
            mocks.VerifyAll(); 
        }
        
        #endregion
        
    }
}
